<template>
  <div class=''>
    <van-nav-bar>
      <template #right>
        <van-icon name="comment-circle-o" size="24" />
        <van-icon name="setting-o" size="24"/>
      </template>
    </van-nav-bar>
    <van-cell class="user">
      <img :src="user.portrait" alt="" class="avtor">
      <p class="username">{{user.userName}}</p>
    </van-cell>
    <van-cell-group inset class="menus">
      <van-row type="flex">
        <van-col class="vip" span="24">
          <span>超级VIP</span>
          <span>全场专栏任意学</span>
          <van-button type="default" size="mini">默认按钮</van-button>
        </van-col>
        <van-col span="12">
          <img src="image/icon/icon1.png" alt="">
          <div class="menu">
            <p>分销中心</p>
            <p>点我赚钱</p>
          </div>
        </van-col>
        <van-col span="12">
          <img src="image/icon/icon2.png" alt="">
          <div class="menu">
            <p>我的客服</p>
            <p>帮助与反馈</p>
          </div>
        </van-col>
        <van-col span="12">
          <img src="image/icon/icon1.png" alt="">
          <div class="menu">
            <p>分销中心</p>
            <p>点我赚钱</p>
          </div>
        </van-col>
        <van-col span="12">
          <img src="image/icon/icon2.png" alt="">
          <div class="menu">
            <p>我的客服</p>
            <p>帮助与反馈</p>
          </div>
        </van-col>
      </van-row>
    </van-cell-group>
    <div data-v-69549244="" class="bottom">
      互联网职业教育平台
    </div>
    <tab-menu :index="0"></tab-menu>
    <van-overlay :show="showLogin" @click="showLogin = false">
      <user-login v-on:login-event="handleLogin"></user-login>
    </van-overlay>
  </div>
</template>

<script>
import store from '@/store';
// eslint-disable-next-line
import { getUserInfo } from '@/services/user';
import TabMenu from '@/components/tabmenu.vue';
import UserLogin from './login.vue';

export default {
  name: 'UserInfo',
  components: {
    UserLogin, TabMenu,
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      if (!store.state.user) {
      // eslint-disable-next-line
        vm.showLogin = true;
      }
    });
  },
  data() {
    return {
      showLogin: false,
      user: {},
    };
  },
  created() {
    if (store.state.user) {
      this.loadUserInfo();
    }
  },
  methods: {
    handleLogin(val) {
      if (val) {
        this.showLogin = false;
        this.loadUserInfo();
      }
    },
    async loadUserInfo() {
      const { data } = await getUserInfo();
      if (data.success) {
        this.user = data.content;
      }
    },
  },
};
</script>

<style lang='less' scoped>
.van-nav-bar .van-icon {
  margin-left: 5px;
}
.bottom {
  color: #ccc;
  font-size: .32rem;
  text-align: center;
  position: absolute;
  bottom: 2rem;
  left: 0;
  width: 100%;
}
.user .van-cell__value {
  display: flex;
}
.user img {
  display: block;
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
.user p {
  margin-left: 15px;
  font-size: 18px;
}

.menus .van-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 5px;
}
.menus .vip {
  color: #fff;
  height: 54px;
  background: url('@/assets/bg.png') top no-repeat;
  background-size: 100% 100%;
  font-size: 12px;
  padding: 0 15px;
}
.menus .vip span:nth-child(1) {
  font-size: 14px;
}
.menus .vip span:nth-child(2) {
  padding: 0 15px;
  flex: 1;
}
.menus .vip .van-button {
  background: linear-gradient(270deg,#f2ca91,#fde8cb);
  border-radius: 2px;
  text-align: center;
  color: #5e3735;
  border: none;
}

.menus .van-col img {
  display: block;
  width: 41px;
  height: 41px;
}
.menus .van-col .menu {
  margin-left: 10px;
}
.menus .van-col .menu p {
  margin: 8px 0;
}
.menus .van-col .menu p:nth-child(1){
  font-size: 14px;
}
.menus .van-col .menu p:nth-child(2){
  font-size: 12px;
  color: #999;
}
</style>
